package shiro.com.service.sys.impl;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import shiro.com.domain.sc.ScZg;
import shiro.com.domain.sys.SysComont;
import shiro.com.domain.sys.vo.SysComontTreeVo;
import shiro.com.mapper.sc.ScZgMapper;
import shiro.com.mapper.sys.SysComontMapper;
import shiro.com.service.sys.ISysComontService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2022-11-21
 */
@Service
public class SysComontServiceImpl implements ISysComontService
{
    @Autowired
    private SysComontMapper sysComontMapper;
    @Autowired
    private ScZgMapper zgMapper;
    /**
     * 查询【请填写功能名称】
     *
     * @param sysComontId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public SysComont selectSysComontBySysComontId(Integer sysComontId)
    {
        return sysComontMapper.selectSysComontBySysComontId(sysComontId);
    }
    @Override
    public List<SysComont> selectSysComontList(SysComont sysComont){
        return sysComontMapper.selectSysComontList(sysComont);
    }
    /**
     * 查询【请填写功能名称】列表
     *
     * @param sysComont 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<SysComontTreeVo> selectTreeList()
    {
        List<SysComont> sysComonts = sysComontMapper.selectSysXXList();

        List<SysComontTreeVo> sysComontTreeVoList = sysComonts.stream().map(item -> {
            SysComontTreeVo sysComontTreeVo = new SysComontTreeVo();
            BeanUtils.copyProperties(item, sysComontTreeVo);

            return sysComontTreeVo;
        }).collect(Collectors.toList());



        List<SysComontTreeVo> collect = sysComontTreeVoList.stream().
                filter(item -> item.getSysComontPid() == 0
        ). map((items) -> {
            items.setChildren(getChildrens(items, sysComontTreeVoList));
            return items;
        }).collect(Collectors.toList());
        return collect;
    }
    private List<SysComont> getChildrens(SysComontTreeVo root, List<SysComontTreeVo> all){
        List<SysComont> children = all.stream().filter(e -> {
            return e.getSysComontPid().equals(root.getSysComontId());
        }).map(e1 -> {
            e1.setChildren(getChildrens(e1,all));
            return e1;
        }) .collect(Collectors.toList());
        return  children;
    }
    /**
     * 新增【请填写功能名称】
     *
     * @param sysComont 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertSysComont(SysComont sysComont)
    {
        return sysComontMapper.insertSysComont(sysComont);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param sysComont 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateSysComont(SysComont sysComont)
    {

        return sysComontMapper.updateSysComont(sysComont);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param sysComontIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysComontBySysComontIds(Integer[] sysComontIds)
    {
        return sysComontMapper.deleteSysComontBySysComontIds(sysComontIds);
    }



    /**
     * 删除【请填写功能名称】信息
     *
     * @param sysComontId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysComontBySysComontId(Integer sysComontId)
    {
        return sysComontMapper.deleteSysComontBySysComontId(sysComontId);
    }

    @Override
    public List<String> selectNameByPhone(String phone){

        List<String> strings = sysComontMapper.selectComontNameBySysComontIds(phone);
        System.out.println(strings);
        return strings;
    }
}
